/**
 * Created by TomSean on 2017/9/1.
 */
var OperationLogList = function($parent) {
    this.$parent = $parent;
    this.sysUtils = new kendoUtils();
    this.init();
    return this;
}

OperationLogList.prototype = {
    init : function () {
        var fieldArray = this.sysUtils.getBindFieldArray(this.$parent.find('.search-panel'));
        var functionArray = [
            {fName : 'find_data', fs : this.findData}
        ];
        this.models = new bindBaseModel(null, fieldArray, functionArray, null);
        this.sysUtils.bindDoucment(this.models, this.$parent, this);
        Utils.createDataDictDropDownList({div:this.$parent.find('#operationBehavior'), parentModelKey:BASIS.OPERATION_BEHAVIOR.ROOT}, this);
        Utils.createDataDictDropDownList({div:this.$parent.find('#belongModel'), parentModelKey:BASIS.MODULE_CODE.ROOT}, this);
        var sHeight = (this.$parent.find('.search-panel')[0].clientHeight);
        var allHeight = (this.$parent[0].clientHeight);
        this.$parent.find('#operation_log_list').height(allHeight-sHeight-2);
        this.initTable();
        this.findData();
    },
    initTable : function() {
        var $this = this;
        var columns = [
            {
                width : 30,
                headerTemplate : '<input type="checkbox" gridId="operation_log_list" onclick="gridCheckAll(this)">',
                template : '<input type="checkbox" name="id" value="${id}">'
            },
            {
                title : '操作人账号',
                field : 'userAccount'
            },
            {
                title : '操作人姓名',
                field : 'userName'
            },
            {
                title : '模块名称',
                template : '${Utils.getModelNameByParentKey(BASIS.MODULE_CODE.ROOT, moduleCode)}'
            },
            {
                title : '操作时间',
                field : 'operatingTime'
            },
            {
                title : '操作IP',
                field : 'operatingIp'
            },
            {
                title : '操作行为',
                template : '${Utils.getModelNameByParentKey(BASIS.OPERATION_BEHAVIOR.ROOT, operationBehavior) }'
            }
        ];
        this.sysUtils.createGird(this.$parent.find('#operation_log_list'),
            {
                selectable: 'single',
                autoSync: true,
                columnMenu: true,
                pageable: {input: true, numeric: false},
                columns: columns,
                dataBound : function() {
                    var $list = $this.$parent.find("#operation_log_list");
                    $list.find("tr").unbind("dblclick");
                    $list.find("tr").dblclick(function(e){
                        var grid = $list.data("kendoGrid");
                        var dataItem = grid.dataItem(grid.select());
                        $this.cache = dataItem;
                        $this.remarkDiv = $this.sysUtils.openWindow($this.remarkDiv, {
                            title : "查看详细",
                            height : "550px",
                            width : "700px",
                            resizable : false,
                            content : "views/parkLotCenter/operationLog/remark.html"
                        });
                    });
                }
            }
        );
    },
    findData : function(e) {
        var $this = this;
        if (!isEmpty(e)) {
            $this = $(e.target).data('that');
        }
        var dataT = {'jsonParam' : JSON.stringify($this.sysUtils.getBindDocJson($this.models.bindFieldArray))};
        var dataSource = $this.sysUtils.getDataSource({url : baseApiPath + 'operation/log/list', data : dataT, dataType : 'odata'});
        var grid = $this.$parent.find('#operation_log_list').data('kendoGrid');
        grid.setDataSource(dataSource);
    }
}